package com.xcity.tools.proto;

import java.io.File;

import naga.x.util.IOUtils;

public class FileWriter {

	private File file;
	private StringBuilder buf;
	
	public FileWriter(File file) {
		this(file, 1024);
	}
	
	public FileWriter(File file, int capacity) {
		this.file = file;
		this.buf = new StringBuilder(capacity);
	}
	
	public FileWriter write(int i) {
		this.buf.append(i);
		return this;
	}
	
	public FileWriter write(long l) {
		this.buf.append(l);
		return this;
	}
	
	public FileWriter write(float f) {
		this.buf.append(f);
		return this;
	}
	
	public FileWriter write(double d) {
		this.buf.append(d);
		return this;
	}
	
	public FileWriter write(char c) {
		this.buf.append(c);
		return this;
	}
	
	public FileWriter write(boolean b) {
		this.buf.append(b);
		return this;
	}
	
	public FileWriter write(Object obj) {
		this.buf.append(obj);
		return this;
	}
	
	public FileWriter write(String text) {
		this.buf.append(text);
		return this;
	}
	
	public FileWriter writeLine(int i) {
		return this.write(i).newLine();
	}
	
	public FileWriter writeLine(long l) {
		return this.write(l).newLine();
	}
	
	public FileWriter writeLine(float f) {
		return this.write(f).newLine();
	}
	
	public FileWriter writeLine(double d) {
		return this.write(d).newLine();
	}
	
	public FileWriter writeLine(char c) {
		return this.write(c).newLine();
	}
	
	public FileWriter writeLine(boolean b) {
		return this.write(b).newLine();
	}
	
	public FileWriter writeLine(Object obj) {
		return this.write(obj).newLine();
	}
	
	public FileWriter writeLine(String text) {
		return this.write(text).newLine();
	}
	
	public FileWriter newLine() {
		this.buf.append(System.lineSeparator());
		return this;
	}
	
	public void flush() {
		IOUtils.write(this.file, this.buf.toString(), IOUtils.UTF8);
	}
	
	public File file() {
		return this.file;
	}
	
	public String fileName() {
		return this.file.getName();
	}

	@Override
	public String toString() {
		return this.buf.toString();
	}
	
}
